<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class Dynamic extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('dynamic');
        if(!$exists){
        $table = $this->table('dynamic', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '动态' ,'id' => 'id' ,'primary_key' => ['id']]);
        $table->addColumn('user_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => true,'comment' => '用户ID',])
			->addColumn('content', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => false,'signed' => true,'comment' => '内容',])
			->addColumn('ip', 'string', ['limit' => 128,'null' => true,'signed' => true,'comment' => 'IP',])
			->addColumn('country', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '国家',])
			->addColumn('province', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '省',])
			->addColumn('city', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '市',])
			->addColumn('district', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '区',])
			->addColumn('adds', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '位置',])
			->addColumn('adds_name', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '位置名称',])
			->addColumn('lng', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '经度',])
			->addColumn('lat', 'string', ['limit' => 50,'null' => true,'signed' => true,'comment' => '纬度',])
			->addColumn('circle_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '圈子ID',])
			->addColumn('circle_name', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '圈子名称',])
			->addColumn('circle_avatar', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '圈子头像',])
			->addColumn('order_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '订单ID',])
			->addColumn('browse', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'default' => 1,'signed' => true,'comment' => '浏览',])
			->addColumn('top', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '置顶',])
			->addColumn('type', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '类型：0 纯文本、1 图文、2 视频、3 音文',])
			->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => true,'comment' => '状态：0 草稿、1 待审核、2 展示、3 不展示、4 驳回、5 用户删除',])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG,'null' => true,'signed' => true,'comment' => '更新时间',])
			->addIndex(['id'], ['name' => '_id'])
            ->create();
        }
    }
}
